/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hello;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
/**
 *
 * @author THANH PHUC
 */
public class Cowboys extends Sprite{
    static final int WIDTH = 32;
    static final int HEIGHT = 48;
    static final int[] FRAME_SEQUENCE = { 3, 2, 1, 2 };
    public Cowboys ()throws Exception
    {
        
        super(Image.createImage("/images/cowboy.png"), 
	  WIDTH, HEIGHT);
        
        //Image a = Image.createImage("/images/cowboy.png");
        //super(a,WIDTH,HEIGHT);
        int myInitialX = 220;
        int myInitialY = 179;
        // we define the reference pixel to be in the middle 
        // of the cowboy image so that when the cowboy turns 
        // from right to left (and vice versa) he does not 
        // appear to move to a different location.
        defineReferencePixel(WIDTH/2, 0);
        setRefPixelPosition(WIDTH/2,0 );
        setFrameSequence(FRAME_SEQUENCE);

    }
    void advance(int tickCount, int Action) {
    if(Action == 0)
    {
        setTransform(TRANS_NONE);
        setFrame(2);
    }
    if(Action == 1) //Phai
    {
        setTransform(TRANS_NONE);
        move(1, 0);
        
        nextFrame();
       
    }
    if(Action == 2) //Trai
    {
        setTransform(TRANS_MIRROR);
        move(-1, 0);
        nextFrame();
        //nextFrame();
    }
    if(Action == 3) //Len
    {
        //setTransform(TRANS_NONE);
        //move(1, 0);
    }
    if(Action == 4) //Xuong
    {
       //setTransform(TRANS_NONE);
       //move(1, 0);
    }
    
    /*
    if(left) {
      // use the mirror image of the cowboy graphic when 
      // the cowboy is going towards the left.
      setTransform(TRANS_MIRROR);
      move(-1, 0);
    } else {
      // use the (normal, untransformed) image of the cowboy 
      // graphic when the cowboy is going towards the right.
      setTransform(TRANS_NONE);
      move(1, 0);
    }*/
    // this section advances the animation: 
    // every third time through the loop, the cowboy 
    // image is changed to the next image in the walking 
    // animation sequence:
    
  }

}
